package com.lovo.sheyingback.service.impl;

import com.lovo.sheyingback.bean.Image;
import com.lovo.sheyingback.dao.ImageMapper;
import com.lovo.sheyingback.service.ImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.util.List;

@Service
@Transactional(propagation = Propagation.REQUIRES_NEW
        ,rollbackFor = {IOException.class})
public class ImageServiceImpl implements ImageService {
    @Autowired
    private ImageMapper imageMapper;
    @Override

    public int save(List<Image> images) throws IOException {
        for(int i = 0;i < images.size();i++){
            if(i == 2){
                throw new IOException();
            }
            imageMapper.insert(images.get(i));

        }
        return 1;
    }
}
